<html>
<body>

<script type="text/javascript" src="/static/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">


    //Cookie OP
    function getsec(str)
    {   
        var str1=str.substring(1,str.length)*1;
        var str2=str.substring(0,1);
        if (str2=="s")
        {   
        return str1*1000;
        }   
        else if (str2=="h")
        {   
        return str1*60*60*1000;
        }   
        else if (str2=="d")
        {   
            return str1*24*60*60*1000;
        }   
    }   

    function setCookie(name,value)
    {   
        var strsec = getsec('d30');
        var exp = new Date();
        exp.setTime(exp.getTime() + strsec*1);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
    }   
    function getCookie(name)
    {   
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
        if(arr=document.cookie.match(reg))
            return unescape(arr[2]);
        else
            return null;
    } 

    function isNull(variable) {
        return ! (typeof(variable) !== "undefined" && variable !== null)
    } 

    accountName = getCookie('accountName');
    accountUuid = getCookie('accountUuid');
    sessionUuid = getCookie('sessionUuid')

    if (sessionUuid == null) {
        sessionUuid = getCookie('sessionId')
    }

    if (!isNull(sessionUuid)) {
        var post_data = {'sessionUuid':sessionUuid, 'accountName':accountName}
        $.post('/valid_session_uuid', post_data, 
            function(rsp){
                console.log(rsp)
                console.log(rsp.is_login)
                if (rsp.is_login) {
                    window.location.href="/home";
                } else {
                    window.location.href="/login";
                }
        })
    } else {
        window.location.href="/login";
    }

</script>

</body>
</html>
